#include "cardmanager.h"

#include <random>  // C++11 随机库

// TODO
// 玩家二路径修改
CardManager::CardManager(int playerType) {
  HowManyCard = 20;
  HowManyCardRemain = 20;
  HowManyCardCanUse = 8;
  isInitNewCard = false;
  card newCard;
  // card_1 打击
  newCard.id = 0;
  newCard.name = "打击";
  newCard.setCardType(0);
  newCard.setAttack(6);
  newCard.setMp(1);
  newCard.setPrice(1);
  newCard.setDescribe("造成6点伤害");
  newCard.setBuff(0);
  newCard.consume = false;

  newCard.setPicPath(":/strike.png");

  // newCard.setPicPath(":/green/test.jpg");

  newCard.setMusicPath("qrc:/new/prefix1/Music/attack1.ogg");
  newCard.actType = 1;
  AllCardGroup.push_back(newCard);
  // card_2 防御
  newCard.id = 1;
  newCard.name = "防御";
  newCard.setCardType(1);
  newCard.setAttack(5);
  newCard.setMp(1);
  newCard.setPrice(1);
  newCard.setDescribe("获得5点格挡");
  newCard.setBuff(0);
  newCard.consume = false;

  newCard.setPicPath(":/defend.png");
  newCard.setMusicPath("qrc:/new/prefix1/Music/skill1.ogg");
  newCard.actType = 2;
  AllCardGroup.push_back(newCard);
  // card_3 放血
  newCard.id = 2;
  newCard.name = "放血";
  newCard.setCardType(2);
  newCard.setAttack(0);
  newCard.setMp(1);
  newCard.setPrice(1);
  newCard.setDescribe("失去2点生命，获得3点能量");
  newCard.setBuff(0);
  newCard.consume = false;
  newCard.setPicPath(":/bloodletting.png");
  newCard.setMusicPath("qrc:/new/prefix1/Music/skill1.ogg");
  newCard.actType = 2;
  AllCardGroup.push_back(newCard);
  // card_4 御血术
  newCard.id = 3;
  newCard.name = "御血术";
  newCard.setCardType(3);
  newCard.setAttack(14);
  newCard.setMp(1);
  newCard.setPrice(1);
  newCard.setDescribe("失去2点生命，造成14点伤害");
  newCard.setBuff(0);
  newCard.consume = false;
  newCard.setPicPath(":/hemokinesis.png");
  newCard.setMusicPath("qrc:/new/prefix1/Music/attack1.ogg");
  newCard.actType = 1;
  AllCardGroup.push_back(newCard);
  // card_5 岿然不动
  newCard.id = 4;
  newCard.name = "岿然不动";
  newCard.setCardType(4);
  newCard.setAttack(30);
  newCard.setMp(2);
  newCard.setPrice(1);
  newCard.setDescribe("获得30点格挡；消耗");
  newCard.setBuff(0);
  newCard.consume = true;
  newCard.setPicPath(":/impervious.png");
  newCard.setMusicPath("qrc:/new/prefix1/Music/skill1.ogg");
  newCard.actType = 2;
  AllCardGroup.push_back(newCard);
  // card_6 暴走
  newCard.id = 5;
  newCard.name = "暴走";
  newCard.setCardType(5);
  newCard.setAttack(5);
  newCard.setMp(1);
  newCard.setPrice(1);
  newCard.setDescribe("造成5点伤害，每使用一次伤害+8");
  newCard.setBuff(5);
  newCard.consume = false;
  newCard.setPicPath(":/rampage.png");
  newCard.setMusicPath("qrc:/new/prefix1/Music/attack1.ogg");
  newCard.actType = 1;
  AllCardGroup.push_back(newCard);
  // card_7 重锤
  newCard.id = 6;
  newCard.name = "重锤";
  newCard.setCardType(6);
  newCard.setAttack(24);
  newCard.setMp(3);
  newCard.setPrice(1);
  newCard.setDescribe("造成24点伤害");
  newCard.setBuff(0);
  newCard.consume = false;
  newCard.setPicPath(":/bludgeon.png");
  newCard.setMusicPath("qrc:/new/prefix1/Music/attack1.ogg");
  newCard.actType = 1;
  AllCardGroup.push_back(newCard);
  // card_8 中和
  newCard.id = 7;
  newCard.name = "中和";
  newCard.setCardType(7);
  newCard.setAttack(4);
  newCard.setMp(0);
  newCard.setPrice(1);
  newCard.setDescribe("造成4点伤害，增加一层虚弱");
  newCard.setBuff(0);
  newCard.consume = false;
  newCard.setPicPath(":/neutralize.png");
  newCard.setMusicPath("qrc:/new/prefix1/Music/skill1.ogg");
  newCard.actType = 1;
  AllCardGroup.push_back(newCard);
  // card_9 痛击
  newCard.id = 8;
  newCard.name = "痛击";
  newCard.setCardType(8);
  newCard.setAttack(8);
  newCard.setMp(2);
  newCard.setPrice(1);
  newCard.setDescribe("造成8点伤害，增加一层易伤");
  newCard.setBuff(0);
  newCard.consume = false;
  newCard.setPicPath(":/bash.png");
  newCard.setMusicPath("qrc:/new/prefix1/Music/attack1.ogg");
  newCard.actType = 1;
  AllCardGroup.push_back(newCard);
  // card_10 子弹时间
  newCard.id = 9;
  newCard.name = "子弹时间";
  newCard.setCardType(9);
  newCard.setAttack(0);
  newCard.setMp(3);
  newCard.setPrice(1);
  newCard.setDescribe("本回合出牌不消耗能量,但回合结束时失去100点生命");
  newCard.setBuff(6);
  newCard.consume = false;
  newCard.setPicPath(":/bullet_time.png");
  newCard.setMusicPath("qrc:/new/prefix1/Music/attack1.ogg");
  newCard.actType = 2;
  AllCardGroup.push_back(newCard);
  // card_11 残杀
  newCard.id = 10;
  newCard.name = "残杀";
  newCard.setCardType(10);
  newCard.setAttack(20);
  newCard.setMp(2);
  newCard.setPrice(1);
  newCard.setDescribe("造成20点伤害，消耗");
  newCard.setBuff(0);
  newCard.consume = true;
  newCard.setPicPath(":/carnage.png");
  newCard.setMusicPath("qrc:/new/prefix1/Music/attack1.ogg");
  newCard.actType = 1;
  AllCardGroup.push_back(newCard);

  CreatOriginalCardGroup(playerType);
}

void CardManager::CreatOriginalCardGroup(int playerType) {
  QString str;

  if (playerType == 1)
    str = "WarriorCards";
  else if (playerType == 2)
    str = "AssassinsCards";

  card newCard;
  const int N = 5, M = 3;  // 初始打击、防御牌数量
  if (playerType == 1) {   // 第一个职业
    for (int i = 0; i < N; i++) {
      CardCanUse.push_back(AllCardGroup[0]);
    }

    for (int i = 0; i < M; i++) {
      CardCanUse.push_back(AllCardGroup[1]);
    }

    // for (int i = 0; i < M; i++) {
    //   CardCanUse.push_back(AllCardGroup[7]);
    // }
    // for(int i=0;i<2;i++){
    //     CardCanUse.push_back(AllCardGroup[2]);
    // }
    // for(int i=0;i<2;i++){
    //     CardCanUse.push_back(AllCardGroup[3]);
    // }
    // for(int i=0;i<1;i++){
    //     CardCanUse.push_back(AllCardGroup[4]);
    // }
    // for(int i=0;i<2;i++){
    //     CardCanUse.push_back(AllCardGroup[5]);
    // }
  } else if (playerType == 2) {  // 第二个职业
    for (int i = 0; i < N; i++) {
      newCard.id = 0;
      newCard.name = "打击";
      newCard.setCardType(1);
      newCard.setAttack(6);
      newCard.setMp(1);
      newCard.setPrice(1);
      newCard.setDescribe("造成6点伤害;打击");
      newCard.setBuff(0);
      newCard.setPicPath(":/strike1.png");
      newCard.setMusicPath("qrc:/new/prefix1/Music/attack1.ogg");
      newCard.actType = 1;
      CardCanUse.push_back(newCard);
    }

    for (int i = 0; i < M; i++) {
      newCard.id = 1;
      newCard.name = "残影";
      newCard.setCardType(2);
      newCard.setAttack(5);
      newCard.setMp(1);
      newCard.setPrice(1);
      newCard.setDescribe("获得5点格挡；残影");
      newCard.setBuff(0);
      newCard.setPicPath(":/blur.png");
      newCard.setMusicPath("qrc:/new/prefix1/Music/skill1.ogg");
      newCard.actType = 2;
      CardCanUse.push_back(newCard);
    }
  }
}

vector<card> CardManager::shopCard() {
  // 随机打乱卡牌组
  vector<card> threeCard;
  int min_value = 2;                    // 包含
  int max_value = AllCardGroup.size();  // 不包含
  for (int i = 0; i < 3; i++) {
    int random_num = QRandomGenerator::global()->bounded(min_value, max_value);
    threeCard.push_back(AllCardGroup[random_num]);
  }

  /*for(int i=0;i<3;i++){
      threeCard.push_back(CardGroup[0]);
      vector<card>::iterator k = CardGroup.begin();
      CardGroup.erase(k);
     }*/

  return threeCard;
}
